import instance from "@/api/instance";

export const timestamp = Date.now();
// 首页轮播图
export const getBanner = () =>
  instance({
    url: "/banner",
    method: "get",
  });

// 首页 获取推荐歌单 limit: 取出数量 , 默认为 30
export const getRecommendPlaylist = (limit) =>
  instance.get(`/personalized?limit=${limit}`);

// 新碟上架
export const topAlbum = ({
  limit = 20,
  offset = 0,
  area = "ALL",
  type = "hot",
  year = "",
  month = "",
}) => {
  return instance.get(
    `/top/album?limit=${limit}&offset=${offset}&area=${area}&type=${type}&year=${year}&month=${month}&timestamp=${timestamp}`
  );
};
// 全部新碟
export const allAlbum = ({ limit = 30, offset = 0, area = "ALL" }) => {
  return instance.get(
    `/album/new?area=${area}&limit=${limit}&offset=${offset}`
  );
};
// 数字专辑详情
export const albumDetail = (id) => {
  return instance.get(`/album?id=${id}`);
};
// 获取歌手专辑
export const artistAlbum = (id, limit = 5) => {
  return instance.get(`/artist/album?id=${id}&limit=${limit}`);
};
// 搜索建议
export const searchSuggest = (keywords,ts) =>
  instance({
    url: `/search/suggest?timestamp=${ts}`,
    data: {
      keywords,
    },
    method: "post",
  });

/* ********* 排行榜 ********* */
// 排行榜
export const topList = () => instance.get("/toplist");
// 所有榜单内容摘要
export const topListDetail = () => instance.get("/toplist/detail");
// 歌单详情  #排行榜也是歌单的一种 s:最近收藏者
export const listDetail = (id = "", s = 8) =>
  instance.get(`/playlist/detail?id=${id}&s=${s}`);

/* ********* 歌手 ********* */
// 热门歌手
export const topArtists = (limit = 30, offset = 0) =>
  instance.get(`/top/artists?offset=${offset}&limit=${limit}`);
// 获取歌手详情
export const artistDetail = (id) => instance.get(`/artist/detail?id=${id}`);
// 获取歌手列表
/*
 * 给评论点赞
 * type: -1:全部; 1:男歌手; 2:女歌手; 3:乐队
 * area: -1:全部; 7华语; 96欧美; 8:日本; 16韩国; 0:其他
 * initial: 按首字母索引查找参数, 热门传-1, #传0
 * limit: 30
 * offset: 0
 */
export const artistList = ({
  type = -1,
  area = -1,
  initial = "",
  limit = 50,
  offset = 0,
}) => {
  return instance.get(
    `/artist/list?type=${type}&area=${area}&initial=${initial}&limit=${limit}&offset=${offset}`
  );
};
// 歌手热门50首歌曲
export const artistTopSong = (id) => instance.get(`/artist/top/song?id=${id}`);
// 歌手专辑
export const artistAlbums = (id, limit = 12, offset = 0) =>
  instance.get(`/artist/album?id=${id}&limit=${limit}&offset=${offset}`);
// 获取歌手描述
export const artistDesc = (id) => instance.get(`/artist/desc?id=${id}`);
// 获取相似歌手
export const simiArtsit = (id) => instance.get(`/simi/artist?id=${id}`);

/* ********* 歌曲 ********* */
// 获取歌曲详情
export const songDetail = (ids) => instance.get(`/song/detail?ids=${ids}`);
// 获取歌曲歌词
export const songLyric = (id) => instance.get(`/lyric?id=${id}`);
// 获取相似歌单
export const simiPlaylist = (id) => instance.get(`/simi/playlist?id=${id}`);
// 获取相似歌曲
export const simiSong = (id) => instance.get(`/simi/song?id=${id}`);

/* ********* 评论 ********* */
// 评论接口
// id : 资源 id, 如歌曲 id,mv id
// type: 数字 , 资源类型 0: 歌曲 1: mv 2: 歌单 3: 专辑4: 电台5: 视频 6: 动态
// sortType: 排序方式, 1:按推荐排序, 2:按热度排序, 3:按时间排序
// cursor: 当sortType为 3 时且页数不是第一页时需传入,值为上一条数据的 time
export const reqComment = ({
  id,
  type,
  pageNo = 1,
  pageSize = 20,
  sortType,
  cursor,
}) => {
  if (sortType === 3 && pageNo !== 1) {
    return instance.get(
      `/comment/new?id=${id}&type=${type}&pageNo=${pageNo}&sortType=${sortType}&cursor=${cursor}&pageSize=${pageSize}`
    );
  } else {
    return instance.get(
      `/comment/new?id=${id}&type=${type}&pageNo=${pageNo}&sortType=${sortType}&pageSize=${pageSize}`
    );
  }
};

/* ********* 歌单 ********* */
//歌单分类
export const getCatlist = () =>
  instance({
    url: "/playlist/catlist",
    method: "get",
  });
// 歌单列表
export const playList = ({ cat = "全部", limit = 50, pageNo = 1 }) => {
  let offset = (pageNo - 1) * limit;
  return instance({
    url: "/top/playlist",
    method: "post",
    params: {
      order: "hot",
      cat,
      limit,
      offset,
    },
  });
};
// 获取歌单详细
export const playlistDetail = (id) =>
  instance.get(`/playlist/detail?id=${id}&s=8`);

/* ********* 电台 ********* */
// 最热主播
export const djToplist = (limit = 30) =>
  instance.get(`/dj/toplist/popular?limit=${limit}`);
// 主播电台catelist
export const djCatelist = () => instance.get("/dj/catelist");
// 节目排行榜
export const djProgramToplist = (limit = 10) =>
  instance({
    url: `/dj/program/toplist?limit=${limit}`,
    method: "get",
  });
// 24 小时节目榜
export const djProgramToplistHours = (limit = 10) =>
  instance({
    url: `/dj/program/toplist/hours?limit=${limit}`,
    method: "get",
  });
// 类别热门电台
export const djRadioHot = ({ limit = 30, cateId, offset = 0 }) => {
  return instance.get(
    `/dj/radio/hot?cateId=${cateId}&limit=${limit}&offset=${offset}`
  );
};

/* ********* 登录 ********* */
//手机登录
export const loginCellphone = (phone, password) => {
  return instance({
    url: "/login/cellphone",
    method: "post",
    params: { phone, password },
  });
};

export default {
  searchSuggest,
  getBanner,
  getRecommendPlaylist,
  topAlbum,
  topList,
  topListDetail,
  listDetail,
  topArtists,
  artistDetail,
  djToplist,
  songDetail,
  reqComment,
  getCatlist,
  playList,
  djCatelist,
  djProgramToplist,
  djProgramToplistHours,
  djRadioHot,
  artistList,
  allAlbum,
  loginCellphone,
  playlistDetail,
  albumDetail,
  artistAlbum,
  artistTopSong,
  artistAlbums,
  artistDesc,
  simiArtsit,
  songLyric,
  simiPlaylist,
  simiSong,
};
